package com.ebt.m.commons.buscomponent.listview;

import android.content.Context;

import com.ebt.m.commons.model.data.BaseDataResult;
import com.ebt.m.commons.model.data.Constants;

import java.util.List;

import io.reactivex.functions.Predicate;

/**
 * Created by andy.wang on 2016/12/13.
 */

public abstract class BaseListPresenter<T extends BaseListContract.IView> extends BasePresenter<T> implements BaseListContract.IPresenter {


    public BaseListPresenter(Context context, T iView) {
        super(context, iView);
    }

//    @Override
//    public List<SectionItem> createSectionItem(List datas) {
//        return null;
//    }

    /**
     * change the footview status according to count of  fetching data
     *
     * @param isLoadNew
     * @param <T>
     * @return
     */
    protected <T> Predicate<BaseDataResult<List<T>>> getFilterForFootviewStatus(final boolean isLoadNew) {
        return listBaseDataResult -> {
            List<T> k = listBaseDataResult.getData();
            if (listBaseDataResult == null || k == null || k.size() == 0) {
                if (!isLoadNew) {
                    iView.setFootStatus(RecyclerFootManger.STATUS_END, true);
                    return false;
                } else {
                    iView.setFootStatus(RecyclerFootManger.STATUS_NORMAL, true);
                    return true;
                }
            }

            if (k.size() < Constants.PAGE_COUNT_LIMIT) {
                iView.setFootStatus(RecyclerFootManger.STATUS_END, true);
                return true;
            } else {
                iView.setFootStatus(RecyclerFootManger.STATUS_LOADING, true);
                return true;
            }
        };
    }
}
